import Util.MysqlUtil
import Util.RedisUtil
import appMain as appMain
from flask import request
import service.QQService as qqService
import dao.myQQInfoDao as myQQ
import Util.JsonUtil as json
app = appMain.app
RedisUtilClass = Util.RedisUtil.RedisUtilClass()
MysqlClass = Util.MysqlUtil.MysqlClass()


# https://docs.go-cqhttp.org/guide/eventfilter.html#%E8%BF%9B%E9%98%B6%E6%8C%87%E5%8D%97   参考文档

@app.route("/qq/onMessAge", methods=['POST', 'GET'])
def onMessAge():
    json = getQueryData()
    print(json)
    post_type = json['post_type']
    if "request" == post_type:
        if "friend" == json['request_type']:
            qqService.add_friend(json)
    return ""

@app.route("/qq/getAllqqInfo", methods=['POST', 'GET'])
def get_all_qq_info():
    allQQ = myQQ.query_all_qq()
    print(type(allQQ))

    return json.toJsonString(allQQ)




def getQueryData():
    json = None
    if request.method == "GET":
        json = request.args.to_dict()
    if request.method == "POST":
        if request.content_type.startswith('application/json'):
            json = request.json
        elif request.content_type.startswith('multipart/form-data'):
            json = request.form
        else:
            json = request.values
    return json
